package com.maimao.spider.processor;

import com.maimao.spider.controller.SpiderController;
import com.maimao.spider.model.Category;
import com.maimao.spider.regex.RegexUtils;
import com.maimao.spider.task.CategoryTask;
import com.maimao.spider.utils.PinYinUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;

/**
 * @author MaoLin Wang
 * @date 2020/11/2419:45
 */
@Component
@Slf4j
public class BrandProcessor implements PageProcessor {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");


    @Override
    public void process(Page page) {

        List<String> all = page.getHtml().xpath("//*[@id=\"J_selector\"]/div[1]/div/div[2]/div[2]/ul//a/text()").all();
        for (int i = 0; i < all.size(); i++) {
            all.set(i, all.get(i).trim());
        }
        page.putField("brandNames", all);


    }

    private String getCateName(String tagA) {
        int from = tagA.indexOf(">");
        return StringUtils.substring(tagA, from + 1, tagA.indexOf("<", from));
    }

    @Override
    public Site getSite() {
        return Site.me().setSleepTime(100).setRetryTimes(3);
    }

}
